package io.renren.modules.app.controller;


import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.app.form.RegisterForm;
import io.renren.modules.hospital.entity.EmrHzInfoEntity;
import io.renren.modules.hospital.service.EmrHzInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/app")
@Api(value = "患者App注册接口", tags = "患者App注册接口")
public class UserAppRegisterController {
    @Autowired
    private EmrHzInfoService userService;

    @PostMapping("user_register")
    @ApiOperation("注册")
    public R register(@RequestBody RegisterForm form) {
        //表单校验
        ValidatorUtils.validateEntity(form);

        EmrHzInfoEntity ysInfo=userService.queryByPhone(form.getMobile());
        if(ysInfo!=null){
            return R.ok("此手机号已被注册");
        }
        EmrHzInfoEntity user = new EmrHzInfoEntity();
        user.setEmrHzPhone(form.getMobile());
        user.setEmrHzPwd(DigestUtils.sha256Hex(form.getPassword()));
        userService.save(user);
        return R.ok();
    }
}
